using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoreData;
using EntityData;
using Helper;
namespace Services
{

    public partial class Stock_VoucherOutDetailService
    {
        readonly IStock_VoucherOutDetailEntity entity;

        public Stock_VoucherOutDetailService()
        {
            this.entity = new Stock_VoucherOutDetailEntity();

        }
        private string StrGetListVODByPID = @"SELECT VOD.*,P.Name as ProductName,PU.Name as UnitName,P.Code as ProductCode  FROM Stock_VoucherOutDetail VOD 
                                                LEFT JOIN Product P ON P.ID=VOD.ProductID
                                                LEFT JOIN Product_Unit PU ON VOD.UnitID=PU.ID
                                                WHERE VOD.Stock_VoucherOutID= {0}";
        #region Main Method

        /// <summary>
        /// Save 
        /// </summary>
        /// <param name="_model"></param>
        /// <returns></returns>
        public long Save(object _model)
        {
            try
            {
                var id = long.Parse(_model.GetType().GetProperty("ID").GetValue(_model, null).ToString());
                if (id == 0)
                {
                    return entity.Save((CoreData.Stock_VoucherOutDetail)_model, Table.Stock_VoucherOutDetail.ToString());
                }
                else
                {
                    return entity.Update((CoreData.Stock_VoucherOutDetail)_model, Table.Stock_VoucherOutDetail.ToString());
                }
            }
            catch { return -1; }
        }

        /// <summary>
        /// Get by ID
        /// </summary>
        /// <param name="_id"></param>
        /// <returns></returns>
        public CoreData.Stock_VoucherOutDetail GetByID(long _id)
        {
            try
            {
                return entity.GetById(_id, Table.Stock_VoucherOutDetail.ToString());
            }
            catch { return null; }
        }

        /// <summary>
        /// Get List
        /// </summary>
        /// <returns></returns>
        public IList<CoreData.Stock_VoucherOutDetail> GetList()
        {
            try
            {
                return entity.GetAll(Table.Stock_VoucherOutDetail.ToString()).ToList();
            }
            catch { return null; }

        }

        /// <summary>
        /// Get List with Linq
        /// </summary>
        /// <returns></returns>
        public IList<CoreData.Stock_VoucherOutDetail> GetListByLINQ(Func<CoreData.Stock_VoucherOutDetail, Boolean> _where)
        {
            try
            {
                return entity.GetMany(_where, Table.Stock_VoucherOutDetail.ToString()).ToList();
            }
            catch { return null; }
        }
        /// <summary>
        /// Get One with Linq
        /// </summary>
        /// <returns></returns>
        public CoreData.Stock_VoucherOutDetail GetOneByLINQ(Func<CoreData.Stock_VoucherOutDetail, Boolean> _where)
        {
            try
            {
                return entity.Get(_where, Table.Stock_VoucherOutDetail.ToString());
            }
            catch { return null; }
        }

        /// <summary>
        /// Get List with search string
        /// </summary>
        /// <returns></returns>
        public IList<CoreData.Stock_VoucherOutDetail> GetList(string _searchstring)
        {
            //search theo tieu chi nao do         
            try
            {
                return entity.GetBySearchString(_searchstring, Table.Stock_VoucherOutDetail.ToString()).ToList();
            }
            catch { return null; }
        }


        /// <summary>
        /// Delete
        /// </summary>
        /// <param name="_model"></param>
        /// <returns></returns>
        public bool Delete(object _model)
        {
            try
            {
                entity.Delete((CoreData.Stock_VoucherOutDetail)_model, Table.Stock_VoucherOutDetail.ToString());
                return true;
            }
            catch { return false; }
        }



        #endregion

        #region Other Method
        public IList<CoreData.Stock_VoucherOutDetail> GetListVODByPID(long _PID)
        {
            //search theo tieu chi nao do         
            try
            {
                return entity.GetByCusTomSQL(String.Format(StrGetListVODByPID, _PID)).ToList();
            }
            catch { return null; }
        }
        #endregion




    }

}
